// import recom from '@/components/regionComponent' //地区组件
import defaultImg from '@/components/defaultImg/defaultImg' //默认图片组件
import findCar from '@/components/down-filters/find-car-filter.vue'
export default {
  components: {
    // recom,
    defaultImg, //默认图片组件
    findCar
  },
  data() {
    return {
      navlist: [{
        name: '发布寻车',
        icon: 'iconfabunew'
      },{
        name: '我的寻车',
        icon: 'iconwodexunjia'
      },{
        name: '我的报价',
        icon: 'iconwodebaojia'
      },{
        name: '我的订单',
        icon: 'iconwodedingdan'
      }],
      hotBrandCommonImgUrl: 'https://files.yzsheng.com/goodimg/brandimg/', //公共的品牌图片
      pageIndex: 1,//当前页
      pageSize: 10,
      searchVal: '',//搜索关键字
      brand: '',//品牌
      specification: -1,//类型
      regionId: '',//省地区id

      dataList: [], //列表
      showimg: false, //默认为空显示图片
      toView: '',
      fixed: false,//是否吸顶
      addindexlist: [],//筛选地址
      // 加载前值为loadmore，加载中为loading，没有数据为nomore
      loadmoreArr: ['loadmore','loading','nomore'],
      loadmore: 0,
      totalpage: 0,
    }
  },
  onLoad() {
    this.getList(1) //寻车列表
  },
  onshow(){
    this.getList(1) //寻车列表
  },
  onBackPress(options) {
	  if (options.from === 'navigateBack') {
	    return false
	  }
	  uni.switchTab({
	      url: '/pages/index/index'
	  })
	  return true
  },
  methods: {
    //点击搜索
    search(val) {
      console.log(val)
      this.getList(1)
    },
    // 筛选列表change
    filterFindCarListChange(e){
      console.log('筛选列表',e)
      if(e.type===0){
        this.brand=e.id
      }else if(e.type===1){
        this.specification=e.id
      }else if(e.type===2){
        this.regionId=e.id
      }
      this.getList(1)

    },

    // 滑倒顶部
    tapscroll() {
      if(!this.fixed){
        uni.pageScrollTo({
				  scrollTop: 120,
				  duration: 100
        })
        this.fixed=true
      }

    },

    // 点击筛选  开启吸顶
    open(val){
      this.tapscroll()

    },
    close(val){
      console.log(val)
    },
    // 寻车列表
    async getList(type) {
      if (type === 1) { //寻车列表初始化
        this.pageIndex = 1
        this.dataList=[]
      } else { //寻车列表翻页
        this.pageIndex += 1
      }
      let data={
			  'pageIndex': this.pageIndex,
			  'pageSize': this.pageSize,
			  'search': this.searchVal,
			  'brand': this.brand,
			  'specification': this.specification,
			  'region_Limit_Id': this.regionId,
        'store_Id': this.$store.state.userInfoDetail.store.storeId
      }

      try{

        const res = await this.$api.findCar.GetCarFindBList(data)

        this.loadmore = 0
        res.data.list.forEach(it => {
          it.facade_Picture.forEach(item => {
            if(item.inColour){
              item.inColour.neiColor=item.inColour.colorCoding?item.inColour.colorCoding.split('/'):[]
            }
            if(item.outerColour){
						  item.outerColour.neiColor=item.outerColour.colorCoding?item.outerColour.colorCoding.split('/'):[]
            }
          })
        })
        this.dataList=this.dataList.concat(res.data.list)
        this.totalpage=res.data.total
        let zs=this.totalpage/this.pageSize
        if(zs>this.pageIndex){
          this.loadmore = 0
        }else{
          this.loadmore = 2
        }
      }catch(e){
        //TODO handle the exception
      }

    },
    //发布寻车，我的寻车，我的报价
    fabuxcclick(type) {
      if (type === 0) { //发布寻车
        uni.navigateTo({
          url: '/pages_findCar/releaseForCar/releaseForCar?type=1'
        })
      } else if (type === 1) { //我的寻车
        uni.navigateTo({
          url: '/pages_findCar/iFoundTheCar/iFoundTheCar'
        })
      } else if (type === 2) { //我的报价
        uni.navigateTo({
          url: '/pages_findCar/myOffer/myOffer'
        })
      } else { //我的订单
        uni.navigateTo({
          url: '/pages_order/orderAdmin/orderAdmin'
        })
      }
    },
    //寻车详情
    Findcardetails(val,type) {
      // type--1 寻车详情 2我要报价  同一页面 根据type不同展示不同内容
      uni.navigateTo({
        url: '/pages_findCar/noQuotationForFindCar/noQuotationForFindCar?id='+val.id+'&storeId='+val.store_Id+'&type='+type
      })
    },
  },
  onReachBottom: function() {
    console.log(2222)
		 if (this.totalpage === 0) {
		 this.getList(1)
    } else {
      let zs = Math.ceil(this.totalpage / this.pageSize) //总共多少页
      // 买车订单
      if (zs > this.pageIndex) {
        this.getList(2)
      } else {
        this.loadmore = 2
      }
    }
  }
}
